package com.winchain.chainbill.bill.biz.send.service.impl;

import com.shell.bee.base.exception.UnCheckException;
import com.shell.bee.base.utils.StringUtil;
import com.winchain.chainbill.bill.base.po.CbOpt;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.service.CbRecService;
import com.winchain.chainbill.bill.biz.send.service.BillMoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("billMoveService")
public class BillMoveServiceImpl implements BillMoveService {
	@Autowired
	private CbRecService cbRecService;

	public void move(CbRec bill, CbOpt opt) {
		String eventCode = opt.getOptCode();
		if (StringUtil.emptyAndNull(eventCode)) {
			this.cbRecService.save(bill);
			return;
		}
		String curState = opt.getCurState();
		String nextState = opt.getNxtState();

		bill.setCurBillState(curState);
		bill.setBillState(nextState);
		int affectedRows = this.cbRecService.updateBillOptimistically(bill);
		if (affectedRows != 1) {
			throw new UnCheckException("����������������������");
		}
	}
}
